package search;

import java.io.IOException;

import com.google.api.client.http.GenericUrl;
import com.google.api.client.http.HttpRequest;
import com.google.api.client.http.HttpRequestFactory;
import com.google.api.client.http.HttpResponse;
import com.google.api.client.http.HttpTransport;
import com.google.api.client.http.javanet.NetHttpTransport;

public class SearchUtils {
	public static String API_KEY = "AIzaSyC8rZ1Y0NBBbhi-0rscsNtKtwCwc8ELI4U";
	
	public static String fetchQueryItemsResult(String query) throws IOException{
		HttpTransport httpTransport = new NetHttpTransport();
		  HttpRequestFactory requestFactory = httpTransport.createRequestFactory();
		  GenericUrl url = new GenericUrl("https://www.googleapis.com/freebase/v1/search");
		  url.put("query", query);
		  url.put("limit", "5");
		  url.put("indent", "true");
		  url.put("key", API_KEY);
		  HttpRequest request = requestFactory.buildGetRequest(url);
		  HttpResponse httpResponse = request.execute();
		  return httpResponse.parseAsString();
	}
}
